package com.shoulder.boot.acl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shoulder.boot.acl.dto.ClientAddDTO;
import com.shoulder.boot.acl.dto.ClientModDTO;
import com.shoulder.boot.acl.dto.ClientQueryDTO;
import com.shoulder.boot.acl.service.ClientService;
import com.shoulder.boot.acl.vo.ClientVo;
import com.shoulder.core.api.ApiResult;
import com.shoulder.core.fetch.BaseIds;
import com.shoulder.core.page.PageSchema;
import com.shoulder.log.annotation.LogAnnotation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户端信息管理
 */
@RestController
@AllArgsConstructor
@RequestMapping("/admin/api/v1/acl/client")
public class ClientController {

    private final ClientService clientService;

    /**
     * 添加客户端信息
     *
     * @param addDTO 客户端信息添加请求体
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @PostMapping
    @LogAnnotation(type = "添加客户端信息")
    public ApiResult<Object> add(@RequestBody @Validated ClientAddDTO addDTO) {
        this.clientService.add(addDTO);
        return ApiResult.ok();
    }

    /**
     * 修改客户端信息
     *
     * @param modDTO 客户端信息修改请求体XXXX
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @PutMapping
    @LogAnnotation(type = "修改客户端信息")
    public ApiResult<Object> mod(@RequestBody @Validated ClientModDTO modDTO) {
        this.clientService.mod(modDTO);
        return ApiResult.ok();
    }

    /**
     * 查询客户端信息分页数据
     *
     * @param queryDTO 客户端信息查询请求体
     * @return 客户端信息分页数据
     * @author 596767880@qq.com
     */
    @LogAnnotation(type = "客户端信息分页查询", record = false)
    @PostMapping("/page")
    public ApiResult<PageSchema<ClientVo>> pageQuery(@RequestBody ClientQueryDTO queryDTO) {
        Page<ClientVo> page = this.clientService.pageQuery(queryDTO);
        return ApiResult.ok(new PageSchema<>(page.getTotal(), page.getRecords()));
    }

    /**
     * 查询客户端信息列表数据
     *
     * @param queryDTO 客户端信息查询请求体
     * @return 客户端信息列表数据
     * @author 596767880@qq.com
     */
    @LogAnnotation(type = "客户端信息列表查询", record = false)
    @PostMapping("/list")
    public ApiResult<List<ClientVo>> list(@RequestBody ClientQueryDTO queryDTO) {
        List<ClientVo> list = this.clientService.listQuery(queryDTO);
        return ApiResult.ok(list);
    }

    /**
     * 批量删除客户端信息
     *
     * @param baseIds 客户端信息id集合
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @PostMapping("/rm")
    @LogAnnotation(type = "批量删除客户端信息")
    public ApiResult<Object> delete(@RequestBody @Validated BaseIds<String> baseIds) {
        this.clientService.batchDel(baseIds);
        return ApiResult.ok();
    }


    /**
     * 根据id删除客户端信息
     *
     * @param id 客户端信息id
     * @return ApiResult<Object>
     * @author 596767880@qq.com
     */
    @DeleteMapping("/{id}")
    @LogAnnotation(type = "删除客户端信息")
    public ApiResult<Object> del(@PathVariable String id) {
        this.clientService.del(id);
        return ApiResult.ok();
    }


    /**
     * 根据id获取客户端信息
     *
     * @param id 客户端信息id
     * @return 客户端信息
     * @author 596767880@qq.com
     */
    @GetMapping("/{id}")
    @LogAnnotation(type = "根据id查询客户端信息", record = false)
    public ApiResult<ClientVo> look(@PathVariable String id) {
        ClientVo look = this.clientService.look(id);
        return ApiResult.ok(look);
    }
}
